package raft

import (
	"fmt"
	"log"
)

// Debugging
const Debug = false

func DPrintf(format string, a ...interface{}) (n int, err error) {
	if Debug {
		log.Printf(format, a...)
	}
	return
}

func (rf *Raft) Lock(pid int) {
	rf.mu.Lock()
	fmt.Printf("%v get the lock", pid)
}
func (rf *Raft) Unlock(pid int) {
	rf.mu.Unlock()
	fmt.Printf("%v release the lock", pid)
}
func min(x int, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}
func max(x int, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func (rf *Raft) getLastLogIndexAndTerm() (index int, term int) {
	//要加锁使用
	if len(rf.logs) > 0 {
		index = rf.logs[len(rf.logs)-1].LogIndex
		term = rf.logs[len(rf.logs)-1].Term
	} else {
		index = rf.lastIncludedIndex
		term = rf.lastIncludedTerm
	}
	return
}
